package com.holly.unit.es.starter;

import com.holly.unit.es.EsOperator;
import com.holly.unit.es.api.EsApi;
import com.holly.unit.es.api.config.EsConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 类描述: ES模块的自动配置
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/4/2 14:36
 */
@Configuration
public class EsAutoConfiguration {

    /**
     * ES操作工具类的配置
     *
     * @author holly
     * @date 2020/12/1 14:40
     */
    @Bean
    @ConditionalOnMissingBean(EsApi.class)
    public EsApi esApi() {
        return new EsOperator(esConfig());
    }

    @Bean
    @ConfigurationProperties(prefix = "holly.elasticsearch")
    public EsConfig esConfig() {
        return new EsConfig();
    }
}
